//
//  MainViewController.m
//  FeiMa
//
//  Created by 艾玩科技 on 17/2/18.
//  Copyright © 2017年 随心. All rights reserved.
//

#import "MainViewController.h"
#import "LXSegmentScrollView.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "LeftPersonInfoViewController.h"
#import "ReceivedorderTableViewCell.h"
#import "OrderViewController.h"
#import "UnFinishedOrderViewController.h"
#import "LogInViewController.h"
#import "NewOrderView.h"
#import "SRRefreshView.h"
#import "QRCodeScanningVC.h"

#import "CancleOrderBackView.h"

@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource,MKMapViewDelegate,CLLocationManagerDelegate,AVAudioPlayerDelegate,SRRefreshDelegate,MKMapViewDelegate>
{
    CLLocationManager *_locationManager;
    MKMapView* _mapView;
    LeftPersonInfoViewController  *personInfoVC;//个人信息界面
    UIButton *grayBtn;//灰色视图
    
    UIButton *getOrCancleOrderBtn;
    NSString *loginToken;
    
    UITableView *tbale;
    NSMutableArray *dataArr;//获取到的已接单列表
    UILabel *redLabel;//小红点的数字
    //播放音频的控件
    AVAudioPlayer *_audioPlayer;
    AVPlayer *_avPlayer;
    //未结单数据数组
    NSMutableArray *unGetOrderListArr;
    
    UIView *lightGrayView;//灰色视图
    NSString *newOrderNum;//订单ID
    
    CancleOrderBackView *cancleOrderV;//取消订单发送回执的view
    
    NSString *cancle_orderNum;//取消订单的订单号
    BOOL isFirst;//判断是否的第一次打开应用
    NSString *notif_orderAddress;
    NSString *notif_orderType;
}
@property (nonatomic, strong) SRRefreshView *slimeView;
@property (nonatomic, strong) NewOrderView *nOrderV;
@property (nonatomic, strong) NSDictionary *unGetOrderDic;

@end

@implementation MainViewController
- (SRRefreshView *)slimeView
{
    if (_slimeView == nil) {
        _slimeView = [[SRRefreshView alloc] init];
        _slimeView.delegate = self;
        _slimeView.upInset = 0;
        _slimeView.slimeMissWhenGoingBack = YES;
        _slimeView.slime.bodyColor = [UIColor grayColor];
        _slimeView.slime.skinColor = [UIColor grayColor];
        _slimeView.slime.lineWith = 1;
        _slimeView.slime.shadowBlur = 4;
        _slimeView.slime.shadowColor = [UIColor grayColor];
        
    }
    return _slimeView;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    
}



-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    
    
    if (lightGrayView) {
        
        [lightGrayView removeFromSuperview];
    }
    if (_nOrderV) {
        [_nOrderV removeFromSuperview];
    }
    
    
    unGetOrderListArr = [[NSMutableArray alloc] init];
    [tbale reloadData];
    [self loadOrderList];
    //AVAudioPlayer
    [self loadAudioWithfileStr:@"来订单了"];
    
    //判断是否是登录后第一次来到这个界面
    //    if (isFirst == YES) {
    //        [self loadDriverNotGetOrderList];
    //    }
    
    //设置tabbar的隐藏属性为NO
    self.tabBarController.tabBar.hidden = YES;
    
    
}

#pragma mark  加载司机未接单接口
-(void)loadDriverNotGetOrderList
{
    [CoreWork UnFinishedOrderWithloginToken:GetUserLoginToken Block:^(id responsObject) {
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
        }
#pragma mark --  --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 0) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            lightGrayView.hidden = YES;
            _nOrderV.hidden = YES;
            
            return ;
        }
#pragma mark -- ok --
        else if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 1) )
        {
            
            unGetOrderListArr = [responsObject objectForKey:@"data"];
            isFirst = NO;
            
            //未结单数组大于0时，音乐响起
            if (unGetOrderListArr.count > 0) {
                
                for (NSDictionary *dic in unGetOrderListArr) {
                    if ([dic[@"ordertype"] longValue] == 1) {
                        notif_orderType = [dic objectForKey:@"helpTypeText"];
                        notif_orderAddress = [dic objectForKey:@"addr"];
                        [self loadnOrderView];
                        [_audioPlayer play];
                        lightGrayView.hidden = NO;
                        _nOrderV.orderTypeLabel.text = [NSString stringWithFormat:@"服务类型：%@",[dic objectForKey:@"helpTypeText"]];
                        _nOrderV.orderAdressLabel.text = [NSString stringWithFormat:@"救援地点：%@",[dic objectForKey:@"addr"]];
                        newOrderNum = [NSString stringWithFormat:@"%@",[dic objectForKey:@"orderNo"]];
                        _nOrderV.getOrderButton.titleStr = @"接单";
                        [_nOrderV.getOrderButton addtimeWithTimeIntValue:600];
                        [_nOrderV.getOrderButton addTarget:self action:@selector(getNewOrderBtnAct:) forControlEvents:UIControlEventTouchUpInside];
                        _nOrderV.getOrderButton.endTimeBlock = ^{
                            [_audioPlayer stop];
                            _audioPlayer = nil;
                            lightGrayView.hidden = YES;
                            _nOrderV.hidden = YES;
                            if (lightGrayView) {
                                lightGrayView.top = KScreenHeight;
                            }
                            if (_nOrderV) {
                                _nOrderV.top = KScreenHeight;
                            }
                        };
                    }
                }
                
            }
        }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //调用退出接口
                [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
                    
                    //                    [[NSUserDefaults standardUserDefaults] setBool:NO  forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
    }];
}





#pragma mark -- 加载提示音播放器 --
-(void)loadAudioWithfileStr:(NSString *)fileStr
{
    //AVAudioPlayer
    //查找本地音乐文件路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:fileStr ofType:@"mp3"];
    
    //构建URL
    NSURL *url2 = [NSURL fileURLWithPath:filePath];
    
    //创建音乐播放器
    _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url2 error:nil];
    
    //根据URL地址来读取音乐文件（写在ViewDidLoad中会自动播放）
    [_audioPlayer prepareToPlay];
    
    _audioPlayer.delegate = self;
    _audioPlayer.numberOfLoops = -1;
}
#pragma mark -- 确定接单按钮的点击方法 --
-(void)getNewOrderBtnAct:(UIButton *)sender
{
    
    [_audioPlayer stop];
    _audioPlayer = nil;
    CLLocation *myLocation = [BNCoreServices_Location getLastLocation];
    NSString *myposition_long = [NSString stringWithFormat:@"%f",myLocation.coordinate.longitude];
    NSString *myposition_lat = [NSString stringWithFormat:@"%f",myLocation.coordinate.latitude];
    //接单
    [CoreWork getOrderWithorderNo:newOrderNum lng:myposition_long lat:myposition_lat loginToken:loginToken Block:^(id responsObject) {
        
        
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [lightGrayView removeFromSuperview];
                [_nOrderV removeFromSuperview];
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
        }
#pragma mark --  --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 0) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                lightGrayView.hidden = YES;
                _nOrderV.hidden = YES;
                
                
                if (lightGrayView) {
                    
                    //                    [lightGrayView removeFromSuperview];
                    lightGrayView.top = KScreenHeight;
                    //                    lightGrayView=nil;
                }
                if (_nOrderV) {
                    //                    [nOrderV removeFromSuperview];
                    //                    nOrderV = nil;
                    _nOrderV.top = KScreenHeight;
                }
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            lightGrayView.hidden = YES;
            _nOrderV.hidden = YES;
            
            if (lightGrayView) {
                
                //                [lightGrayView removeFromSuperview];
                lightGrayView.top = KScreenHeight;
            }
            if (_nOrderV) {
                //                [nOrderV removeFromSuperview];
                _nOrderV.top = KScreenHeight;
            }
            
            return ;
        }
#pragma mark -- ok --
        else if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 1) )
        {
            
            //            [lightGrayView removeFromSuperview];
            //            [nOrderV removeFromSuperview];
            
            lightGrayView.top = KScreenHeight;
            _nOrderV.top = KScreenHeight;
            //接单后跳转至接单界面
            OrderViewController *orderVC = [[OrderViewController alloc] init];
            orderVC.selectTimeStr = @"1";
            orderVC.orderNumberStr = newOrderNum;
            orderVC.seveiceTypeStr = notif_orderType;
            orderVC.seveiceAdrssStr = notif_orderAddress;
            [self.navigationController pushViewController:orderVC animated:YES];
        }
        
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //                [lightGrayView removeFromSuperview];
                //                [nOrderV removeFromSuperview];
                
                lightGrayView.top = KScreenHeight;
                _nOrderV.top = KScreenHeight;
                //调用退出接口
                [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
                    //                    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
        
        
    }];
}
#pragma mark -- 加载新订单界面view
-(void)loadnOrderView
{
    
#pragma mark  --  灰色视图 --
    lightGrayView = [[UIView alloc] initWithFrame:self.view.frame];
    lightGrayView.backgroundColor =[UIColor colorWithRed:0.616 green:0.620 blue:0.608 alpha:1.00];
    lightGrayView.alpha = 0.6;
    lightGrayView.hidden = YES;
    [self.view addSubview:lightGrayView];
    
    lightGrayView.userInteractionEnabled = YES;
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView:)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    //    PrivateLetterTap.delegate= self;
    [lightGrayView addGestureRecognizer:PrivateLetterTap];
    
    _nOrderV = [[[NSBundle mainBundle] loadNibNamed:@"NewOrderView" owner:nil options:nil] lastObject];
    _nOrderV.frame = CGRectMake(30, (KScreenHeight -  163)/2.0f, KScreenWidth - 30 *2, 163);
    
    [self.view addSubview:_nOrderV];
    
}

#pragma mark ---"头像"点击触发的方法，完成跳转
- (void)tapAvatarView: (UITapGestureRecognizer *)gesture
{
    lightGrayView.hidden = YES;
    //    if (nOrderV) {
    
    _nOrderV.hidden = YES;
    //    }
    //    if (cancleOrderV) {
    cancleOrderV.hidden = YES;
    //    }
    //    [nOrderV removeFromSuperview];
    //    [cancleOrderV removeFromSuperview];
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [_audioPlayer stop];
    _audioPlayer = nil;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"飞马救援";
#pragma mark -- 取消订单，发送回执 --
    [[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(cancleOrderAction:) name:@"cancleOrderNotif" object:nil  ];
    
#pragma mark -- 有新订单，服务商分配给司机 --
    [[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(AssignedOrderAction:) name:@"ServiceProviderAssignedOrderNotif" object:nil ];
#pragma mark -- 有新订单，司机接单 --
    [[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(driverGetNewOrderAction:) name:@"DriverGetNewOrderNotif" object:nil ];
    dataArr = [[NSMutableArray alloc] init];
    loginToken  =  GetUserLoginToken;
    isFirst = YES;
    
    //这是最主要的界面
    //iOS7新增属性
    self.automaticallyAdjustsScrollViewInsets=NO;
    //“地图“ 和 ”已接订单“ 的两个数组
    NSMutableArray *array=[NSMutableArray array];
    for (int i =0; i<1; i++) {
        
        if (i==0) {
            //加载地图控件
            [self initGUI];
        }
        
        [array addObject:_mapView];
    }
    
    //    tbale=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - )];
    tbale = [[UITableView alloc] init];
    tbale.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight +64);
    
    tbale.delegate=self;
    tbale.dataSource=self;
    tbale.separatorStyle = UITableViewCellSeparatorStyleNone;
    tbale.rowHeight=100;
    [tbale reloadData];
    [tbale addSubview:self.slimeView];
    [array addObject:tbale];
    
    //加载接单列表
    [self loadOrderList];
    //标题选择器
    LXSegmentScrollView *scView=[[LXSegmentScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height) titleArray:@[@"地图",@"已接订单"] contentViewArray:array];
    scView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:scView];
    //    tbale.height = KScreenHeight - 64 - scView.height;
    //小红点
    redLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScreenWidth/2.f +KScreenWidth/4.f +KScreenWidth/16.f+5, 3, 15, 15)];
    redLabel.layer.cornerRadius = redLabel.width/2.f;
    redLabel.layer.masksToBounds =YES;
    redLabel.textAlignment = NSTextAlignmentCenter;
    
    redLabel.font = [UIFont systemFontOfSize:10];
    redLabel.textColor = [UIColor whiteColor];
    redLabel.backgroundColor = [UIColor redColor];
    [scView addSubview:redLabel];
    
    
    //加载左侧导航项
    [self navigationConfig];
    //加载接单按钮
    [self loadGetORCancleOrderBtn];
    //调用开始接单的方法
    [self startGetOrder];
    
    
}
#pragma mark -- 接到取消订单的通知 --
-(void)cancleOrderAction:(NSNotification *)notifi
{
#pragma mark  --  灰色视图 --
    lightGrayView = [[UIView alloc] initWithFrame:self.view.frame];
    lightGrayView.backgroundColor =[UIColor colorWithRed:0.616 green:0.620 blue:0.608 alpha:1.00];
    lightGrayView.alpha = 0.6;
    [self.view addSubview:lightGrayView];
    lightGrayView.hidden = NO;
    
    lightGrayView.userInteractionEnabled = YES;
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView:)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    //    PrivateLetterTap.delegate= self;
    [lightGrayView addGestureRecognizer:PrivateLetterTap];
    cancleOrderV = [[[NSBundle mainBundle] loadNibNamed:@"CancleOrderBackView" owner:nil options:nil] lastObject];
    cancleOrderV.frame = CGRectMake(30, (KScreenHeight -cancleOrderV.height)/2.0f, KScreenWidth - 30 *2, 286);
    
    [self.view addSubview:cancleOrderV];
    [cancleOrderV.sendBackBtn setBackgroundColor:[UIColor colorWithRed:0.600 green:0.600 blue:0.600 alpha:1.00]];
    //赋值 （车牌号，汽车描述，救援地点）
    cancleOrderV. carNumLabel.text = [NSString stringWithFormat:@"车牌号：%@",[notifi.userInfo objectForKey:@"cancleOredr_cardNum"]];
    cancleOrderV. carDescriptionLabel.text = [NSString stringWithFormat:@"汽车描述：%@",[notifi.userInfo objectForKey:@"cancleOredr_cardesc"]];
    cancleOrderV. adressLabel.text = [NSString stringWithFormat:@"救援地点：%@",[notifi.userInfo objectForKey:@"cancleOredr_addr"]];
    //取消订单的订单号
    cancle_orderNum = [NSString stringWithFormat:@"%@",[notifi.userInfo objectForKey:@"cancleOredr_orderNo"]];
    
    //我已知晓
    cancleOrderV.ifKonwBtn.layer.borderWidth = 1;
    cancleOrderV.ifKonwBtn.selected = NO;
    cancleOrderV.ifKonwBtn.layer.borderColor =[UIColor colorWithRed:0.600 green:0.600 blue:0.600 alpha:1.00].CGColor;
    [cancleOrderV.ifKonwBtn addTarget:self action:@selector(ifKnowBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //发送回执按钮的点击方法
    [cancleOrderV.sendBackBtn addTarget:self action:@selector(sendBackAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self loadAudioWithfileStr:@"cancleOrder"];
    [_audioPlayer play];
}
//是否已知晓
-(void)ifKnowBtnAct:(UIButton *)sender
{
    
    
    
    if (cancleOrderV.ifKonwBtn.selected == YES)  {
        
        cancleOrderV.ifKonwBtn.selected = YES;
        [cancleOrderV.sendBackBtn setBackgroundColor:[UIColor colorWithRed:0.333 green:0.678 blue:0.953 alpha:1.00]];
        sender.layer.borderWidth = 1;
        sender.layer.borderColor =[UIColor colorWithRed:1.000 green:0.000 blue:0.475 alpha:1.00].CGColor;
        
    }
    else
    {
        [cancleOrderV.sendBackBtn setBackgroundColor:[UIColor colorWithRed:0.600 green:0.600 blue:0.600 alpha:1.00]];
    }
}
#pragma mark -- 发送回执按钮的点击方法 --
-(void)sendBackAction:(UIButton *)sender
{
    if (cancleOrderV.ifKonwBtn.selected == NO) {
        return;
    }
    //获取当前位置
    CLLocation *myLocation = [BNCoreServices_Location getLastLocation];
    
#pragma mark -- 发送回执的接口 -- 参数未传
    [CoreWork cancleBackWithorderNo:cancle_orderNum lng:[NSString stringWithFormat:@"%f", myLocation.coordinate.longitude] lat:[NSString stringWithFormat:@"%f", myLocation.coordinate.latitude] loginToken:GetUserLoginToken Block:^(id responsObject) {
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
            
        }
        
#pragma mark -- 报错 --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 0) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //调用退出接口
                [CoreWork logOutWithloginToken:GetUserLoginToken Block:^(id responsObject) {
                    //                    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
#pragma mark 回执发送成功
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == 1))
        {
            
            
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [lightGrayView removeFromSuperview];
                [cancleOrderV removeFromSuperview];
                [_audioPlayer stop];
                _audioPlayer = nil;
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
        }
        
        
    }];
    [_audioPlayer stop];
    _audioPlayer = nil;
}
#pragma mark -- 服务商分配司机的通知 --
-(void)AssignedOrderAction:(NSNotification *)notif
{
    //AVAudioPlayer
    [self loadAudioWithfileStr:@"newOrder"];
    [_audioPlayer play];
    
}


#pragma  mark -- 司机接收到新订单的通知 --
-(void)driverGetNewOrderAction:(NSNotification *)notif
{
    
    [self loadnOrderView];
    lightGrayView.hidden = NO;
    //为新订单赋值
    _nOrderV.orderTypeLabel.text = [NSString stringWithFormat:@"服务类型：%@",[notif.userInfo objectForKey:@"drivergetorder_helpTypeText"]];
    _nOrderV.orderAdressLabel.text = [NSString stringWithFormat:@"救援地点：%@",[notif.userInfo objectForKey:@"drivergetorder_addr"]];
    newOrderNum = [NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"drivergetorder_orderNo"]];
    //通知传过来的数据，赋值给多久能到界面
    notif_orderType =[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"drivergetorder_helpTypeText"]];
    notif_orderAddress = [NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"drivergetorder_addr"]];
    
    
    _nOrderV.getOrderButton.titleStr = @"接单";
    [_nOrderV.getOrderButton addtimeWithTimeIntValue:600];
    [_nOrderV.getOrderButton addTarget:self action:@selector(getNewOrderBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    [self loadAudioWithfileStr:@"来订单了"];
    [_audioPlayer play];
    
    
}
#pragma mark -- 接单列表 --
-(void)loadOrderList
{
    [CoreWork orderListWithloginToken:loginToken Block:^(id responsObject) {
        
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
        }
#pragma mark -- 未登录 --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == -1) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //调用退出接口
                [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
                    //                     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
        dataArr = [responsObject objectForKey:@"data"];
        redLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)dataArr.count];
        //接单量大于xx时用..代替
        if (dataArr.count > 99) {
            redLabel.text = @"..";
        }
        [tbale reloadData];
        
    }];
}


#pragma mark -- 加载开始接单OR结束接单按钮 --
-(void)loadGetORCancleOrderBtn
{
    getOrCancleOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    getOrCancleOrderBtn.frame = CGRectMake((KScreenWidth - 100.f )/2.f, KScreenHeight - 100 - 50 -64-44, 100, 100);
    [getOrCancleOrderBtn setTitle:@"开始\n接单" forState:UIControlStateNormal];
    getOrCancleOrderBtn.titleLabel.numberOfLines = 0;
    [getOrCancleOrderBtn setTitle:@"停止\n接单" forState:UIControlStateSelected];
    getOrCancleOrderBtn.layer.cornerRadius = getOrCancleOrderBtn.width /2.0f;
    getOrCancleOrderBtn.layer.masksToBounds = YES;
    getOrCancleOrderBtn.backgroundColor =[UIColor colorWithRed:0.000 green:0.757 blue:0.612 alpha:1.00];
    getOrCancleOrderBtn.titleLabel.textColor = [UIColor whiteColor];
    getOrCancleOrderBtn.selected = YES;
    getOrCancleOrderBtn.layer.borderWidth = 2;
    getOrCancleOrderBtn.layer.borderColor = [[UIColor colorWithRed:1.000 green:1.000 blue:1.000 alpha:1.00] CGColor];
    [getOrCancleOrderBtn addTarget:self action:@selector(getOrCancleOrderAct:) forControlEvents:UIControlEventTouchUpInside];
    [_mapView addSubview:getOrCancleOrderBtn];
}
//开始 OR 停止 接单
-(void)getOrCancleOrderAct:(UIButton *)sender
{
    sender.selected = !sender.selected;
    
    if (sender.selected == YES) {
        
        [self startGetOrder];
        
        
    }
    else if (sender.selected == NO)
    {
        //停止接单
        [CoreWork startGetOrderWithloginToken:loginToken allowOrder:@"0" Block:^(id responsObject) {
            
            if (![responsObject isKindOfClass:[NSDictionary class]]) {
                
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                
                [alert addAction:sure];
                [self presentViewController:alert animated:YES completion:nil];
                sender.selected = NO;
                return ;
                
            }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
            if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    //调用退出接口
                    [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
                        //                         [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                        [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                    }];
                    
                }];
                
                [alert addAction:sure];
                [self presentViewController:alert animated:YES completion:nil];
                
                return ;
            }else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == 0))
            {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                
                [alert addAction:sure];
                [self presentViewController:alert animated:YES completion:nil];
                
                return ;
            }
            
            
            
        }];
    }
}
#pragma mark  -- 开始接单 --
-(void)startGetOrder
{
    //开始接单  1 是可接单  0是不可接单
    [CoreWork startGetOrderWithloginToken:loginToken allowOrder:@"1" Block:^(id responsObject) {
        
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            getOrCancleOrderBtn.selected = NO;
            return ;
            
        }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //调用退出接口
                [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
                    //                     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == 0))
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
#pragma mark -- 加载司机未接单的接口，达到刷新的效果 --
        [self loadDriverNotGetOrderList];
    }];
    
}
#pragma mark 添加地图控件
-(void)initGUI{
    //地图控件
    _mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0, 64*2, KScreenWidth, KScreenHeight +64 )];
    //设置代理
    _mapView.delegate=self;
    
    
    CLLocationManager *locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;
    //请求定位服务
    _locationManager=[[CLLocationManager alloc]init];
    if(![CLLocationManager locationServicesEnabled]||[CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorizedWhenInUse){
        
        [_locationManager requestWhenInUseAuthorization];
        
    }
    
    
    //用户位置追踪(用户位置追踪用于标记用户当前位置，此时会调用定位服务)
    _mapView.userTrackingMode=MKUserTrackingModeFollow;
    
    //设置地图类型
    _mapView.mapType=MKMapTypeStandard;
    
    
    
}

#pragma mark - 加载左侧导航项 -
- (void)navigationConfig {
    //个人信息界面初始化
    personInfoVC = [[LeftPersonInfoViewController alloc] init];
    personInfoVC.view.frame = CGRectMake(-(KScreenWidth  *2.0 / 3.0 - 30), 0, KScreenWidth  *2.0 / 3.0 - 30, KScreenHeight);
    UIButton *jiantouBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    jiantouBtn.frame = CGRectMake(0, 12, 50, 50);
    [jiantouBtn setBackgroundImage:[UIImage imageNamed:@"icon_user.png"] forState:UIControlStateNormal];
    [jiantouBtn addTarget:self action:@selector(ShowPersonInfoAct:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:jiantouBtn];
    
}
//左侧导航项的点击方法
-(void)ShowPersonInfoAct:(UIButton *)sender
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    //灰色模糊视图按钮
    grayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    grayBtn.frame = self.view.frame;
    grayBtn.backgroundColor =[UIColor colorWithRed:0.376 green:0.384 blue:0.365 alpha:1.00];
    grayBtn.alpha = 0.6;
    [grayBtn addTarget:self action:@selector(grayBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:grayBtn];
    
    
    //如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    
    [window addSubview: personInfoVC.view];
    [UIView animateWithDuration:0.5 animations:^{
        personInfoVC.view.transform = CGAffineTransformMakeTranslation(personInfoVC.view.width, 0);
    }];
    //退出登录
    [personInfoVC.logOutBtn addTarget:self action:@selector(logOutBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    //车辆签出
    [personInfoVC.SignButton addTarget:self action:@selector(SignButtonAct:) forControlEvents:UIControlEventTouchUpInside];
    
    //未完成订单
    [personInfoVC.UnFinishedBtn addTarget:self action:@selector(unFinishedBtnAct:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark -- 个人信息界面 未完成订单按钮的点击方法 --
-(void)unFinishedBtnAct:(UIButton *)sender
{
    [UIView animateWithDuration:0.3 animations:^{
        personInfoVC.view.transform = CGAffineTransformMakeTranslation(-personInfoVC.view.width, 0);
        grayBtn.backgroundColor = [UIColor clearColor];
        //
        [grayBtn removeFromSuperview];
        UnFinishedOrderViewController *unfinishedOrderVC = [[UnFinishedOrderViewController alloc] init];
        [self.navigationController pushViewController:unfinishedOrderVC animated:YES];
    }];
    
}
#pragma mark -- 个人信息界面 车辆签出按钮的点击方法 --
-(void)SignButtonAct:(UIButton *)sender
{
    
#pragma mark  -- 车辆签出接口 --
    [CoreWork signOutWithloginToken:loginToken Block:^(id responsObject) {
        
        
        
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
        }
#pragma mark -- 退出失败 --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == -1) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
        
        [UIView animateWithDuration:0.3 animations:^{
            personInfoVC.view.transform = CGAffineTransformMakeTranslation(-personInfoVC.view.width, 0);
            grayBtn.backgroundColor = [UIColor clearColor];
            //
            [grayBtn removeFromSuperview];
            
            //返回到‘扫描界面’
            [self.navigationController pushViewController:[QRCodeScanningVC new] animated:YES];
            //            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
            
        }];
        
        
    }];
    
}
#pragma  mark  -- 个人信息界面 退出按钮的点击方法 --
-(void)logOutBtnAct:(UIButton *)sender
{
#pragma mark -- 退出登录接口 --
    [CoreWork logOutWithloginToken:loginToken Block:^(id responsObject) {
        
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
            
        }
#pragma mark -- 退出失败 --
        if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 0) ) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        
        DeleteUserInfo;
        
        [UIView animateWithDuration:0.3 animations:^{
            personInfoVC.view.transform = CGAffineTransformMakeTranslation(-personInfoVC.view.width, 0);
            grayBtn.backgroundColor = [UIColor clearColor];
            //
            [grayBtn removeFromSuperview];
            
            //（输入手机号登录进来）  返回到‘未登录界面’
            
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[LogInViewController new]];
            nav.title = @"登录";
            [self presentViewController:nav animated:YES completion:nil];
        }];
    }];
    
    
}

#pragma mark - 模糊视图按钮的点击方法 -
-(void)grayBtnAct:(UIButton *)sender
{
    [UIView animateWithDuration:0.7 animations:^{
        personInfoVC.view.transform = CGAffineTransformMakeTranslation(-personInfoVC.view.width, 0);
        grayBtn.backgroundColor = [UIColor clearColor];
        //
        [grayBtn removeFromSuperview];
    }];
    
}

#pragma mark 创建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 已接订单的cell
    ReceivedorderTableViewCell *receivedOrderCell =[tableView dequeueReusableCellWithIdentifier:@"receiveorderCell"];
    
    if (!receivedOrderCell) {
        
        receivedOrderCell =[[[NSBundle mainBundle] loadNibNamed:@"ReceivedorderTableViewCell" owner:nil options:nil] lastObject];
        
    }
    //服务类型
    receivedOrderCell.seveiceTypeLabel.text= [NSString stringWithFormat:@"%@",[dataArr[indexPath.row] objectForKey:@"helpTypeText"]];
    //救援地点
    receivedOrderCell.seveiceAddressLabel.text= [NSString stringWithFormat:@"救援地点：%@",[dataArr[indexPath.row] objectForKey:@"addr"]];
    //服务类型
    receivedOrderCell.passTimeLabel.text= [NSString stringWithFormat:@"已接订单：%@",[dataArr[indexPath.row] objectForKey:@"passtime"]];
    receivedOrderCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    return receivedOrderCell;
    
    
    
}

//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 77;
    
}
//cell个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return dataArr.count;;
}
//cell点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    OrderViewController *orderVC = [[OrderViewController alloc] init];
    orderVC.orderNumberStr = [NSString stringWithFormat:@"%@",[dataArr[indexPath.row] objectForKey:@"orderNo"]];
    //    orderVC.istrailStr =[NSString stringWithFormat:@"%@",[dataArr[indexPath.row] objectForKey:@"istrail"]];
    [self.navigationController pushViewController:orderVC animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}

//显示地图的时候设置地图的缩放比例，MKCoordinateRegion ，MKCoordinateSpan，或者设置zoomlevel

#pragma mark - scrollView delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_slimeView) {
        [_slimeView scrollViewDidScroll];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (_slimeView) {
        [_slimeView scrollViewDidEndDraging];
        
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [_slimeView endRefresh];
    
    [self loadOrderList];
    [tbale reloadData];
}

#pragma mark - slimeRefresh delegate
//加载更多
- (void)slimeRefreshStartRefresh:(SRRefreshView *)refreshView
{
    [_slimeView endRefresh];
    
    
    [self loadOrderList];
    [tbale reloadData];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if (_nOrderV) {
        
        _nOrderV.hidden = YES;
        //
        
        _nOrderV.top = KScreenHeight;
        
        [_nOrderV removeFromSuperview];
    }
    if (lightGrayView) {
        lightGrayView.hidden =YES;
        //
        
        lightGrayView.top = KScreenHeight;
        [lightGrayView removeFromSuperview];
    }
    
    if (cancleOrderV) {
        cancleOrderV.hidden =YES;
        //
        cancleOrderV.top = KScreenHeight;
        
        [cancleOrderV removeFromSuperview];
    }
    _nOrderV = nil;
}
@end
